package com.ggh.jinjilive.dialog.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.ggh.jinjilive.R;
import com.ggh.jinjilive.databinding.ItemTvliveRoomPersonnelBinding;
import com.ggh.jinjilive.listener.AddItemOnClickListener;
import com.ggh.jinjilive.views.live.pk.commondef.AnchorInfo;

import java.util.List;

public class OnlineAdapter extends RecyclerView.Adapter<OnlineAdapter.ItemViewHolder> {
    private List<AnchorInfo> anchorInfoList;


    public void setAdd(List<AnchorInfo> anchorInfoList){
        this.anchorInfoList = anchorInfoList;
        notifyDataSetChanged();
    }

    private AddItemOnClickListener addItemOnClickListener;
    public void setAddItemOnClickListener(AddItemOnClickListener addItemOnClickListener){
        this.addItemOnClickListener = addItemOnClickListener;
    }

    @NonNull
    @Override
    public OnlineAdapter.ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemTvliveRoomPersonnelBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_tvlive_room_personnel, parent, false);
        return new ItemViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull ItemViewHolder holder, int position) {
        AnchorInfo anchorInfo = anchorInfoList.get(position);
        if(null != anchorInfo){
            //头像
            Glide.with(holder.binding.rivHeadLike).load(anchorInfo.userAvatar).into(holder.binding.rivHeadLike);
            //名称
            holder.binding.tvUserName.setText(anchorInfo.userName);
            //点击事件
            holder.binding.buttonInvite.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if(null != addItemOnClickListener){
                        addItemOnClickListener.onSkipClicked(position,anchorInfo);
                    }
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return null == anchorInfoList ? 0 : anchorInfoList.size();
    }

    public class ItemViewHolder extends RecyclerView.ViewHolder {
        ItemTvliveRoomPersonnelBinding binding;

        public ItemViewHolder(@NonNull ItemTvliveRoomPersonnelBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }
}